<?php
/**
 *驾校评论控制器----sunxue
 */

namespace Admin\Controller;

class SchoolCommentController extends ComController
{

    //驾校评论列表
    public  function  index(){


        //搜索值
        $p= intval($_GET['p'])?$_GET['p']:1;

        $record = M('school_comment');
        $pagesize = 2;#每页数量
        $offset = $pagesize * ($p - 1);//计算记录偏移量
        $prefix = C('DB_PREFIX');
        // $where = '1=1';
        //公司名称
        $UserName = isset($_GET['username']) ? htmlentities($_GET['username']) : '';
        //手机号
        $user = isset($_GET['user']) ? htmlentities($_GET['user']) : '';

        if ($UserName) {
            $where = " u.username like '%{$UserName}%' ";
        }
        if ($user) {
            $where = " m.user like '%{$user}%' ";
        }


//
//        dump($where);
//        exit;



        $SchoolComment=M('school_comment');



        $count = $SchoolComment->join('as sc left join  driving_member  as m    on sc.school_id=m.uid')
            ->join(' left join  driving_user  as u   on sc.learner_id=u.id')
            ->field('sc.content, sc.status, m.user, u.username ')
            ->where($where)
            ->order('sc.id asc' )
            ->count();




        $data = $SchoolComment->join('as sc left join  driving_member  as m    on sc.school_id=m.uid')
            ->join(' left join  driving_user  as u   on sc.learner_id=u.id')
            ->field('sc.id, sc.content, sc.status, m.user, u.username ')
            ->where($where)
            ->order('sc.id asc' )
            ->limit($offset . ',' . $pagesize)
            ->select();





        $page = new \Think\Page($count, $pagesize);
        $page = $page->show();

//
//        dump($data);
//        dump($SchoolComment->getLastSql());
//        exit;

        $this->assign('data', $data);
        $this->assign('page', $page);
        $this->display();











    }








}